import axios from 'axios'
import {BASEURL} from "/@/setting.js"
import  {useStore} from "vuex"
import { Toast } from 'vant';
let count = 0; 
export function request(config){
    count+=1;
    const store = useStore()
    if(store)store.commit("changeLoadingTrue");

    const instance = axios.create({
        method:"post",
        baseURL:BASEURL,
        timeout:60000,
    })
    instance.interceptors.response.use(res=>{
        return res.data
    })
   return instance(config).then(res=>{
        count-=1;
        if(count==0){
            if(store)store.commit("changeLoadingFalse");
        }
        return res
    }).catch(err=>{
        count-=1;
        if(count==0){
            if(store)store.commit("changeLoadingFalse");
        }
        Toast("网络错误 请刷新页面再试")
        return err
    })
}